package ua.kratik.seabattle.game.enums;

import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum Direction {
					/** Up */
					NORTH(1, "North"),
	/** Left */
	WEST(3, "West"), 					/** Right */
										EAST(4, "East"),
					/** Down */
					SOUTH(2, "South");

	private int id;
	private String value;

	private static Random random = new Random();
	
	private static Logger logger = LoggerFactory.getLogger(Direction.class);

	/**
	 * @param id
	 *            - is used as unique identifier of this enum element in data
	 *            storage
	 * @param value
	 *            - is used to describe this element in data storage. Is not
	 *            case sensitive therefore hardcoded
	 *            <code>value = "North"</code> and <code>"north"</code> in data
	 *            storage are equal
	 */
	Direction(int id, String value) {
		this.id = id;
		this.value = value;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @return the descriptive value
	 */
	public String getValue() {
		return value;
	}

	public static Direction getRundomHorizontalDirection() {
		if (random.nextBoolean()) {
			return WEST;
		} else {
			return EAST;
		}
	}

	public static Direction getRundomVerticalDirection() {
		if (random.nextBoolean()) {
			return NORTH;
		} else {
			return SOUTH;
		}
	}

	public static Direction getRandomDirection() {
		switch (random.nextInt() % 4) {
		case 0:
			return NORTH;
		case 1:
			return SOUTH;
		case 2:
			return WEST;
		case 3:
			return EAST;
		default:
			logger.warn("Illegal case value");
			return NORTH;
		}
	}

}
